<?php
/*
Module: STRING.php
Description: An Extension Library to Support string manipulation functions
*/

// Library Class Definition
class STRING {
	function tag_UCASE($node) {
		$eng = $node->getEngine();
		$node->push();
		$node->evalNodes();
		$eng->setContent(strtoupper($eng->getContent()));
		$node->pop();
	}

	function tag_LCASE($node) {
		$eng = $node->getEngine();
		$node->push();
		$node->evalNodes();
		$eng->setContent(strtolower($eng->getContent()));
		$node->pop();
	}

	function tag_REPLACE($node) {
		if(!$node->hasParam("search", "search") ||
			!$node->hasParam("replace", "replace"))
			return;
		$search = $node->getParam("search");
		$var = $node->getParam("replace");
		$replace = $node->evalParam($var);
		if ($replace === NULL)
			$replace = "NULL";
		$eng = $node->getEngine();
		$node->push();
		$node->evalNodes();
		$content = $eng->getContent();
		$content = str_replace($search, $replace, $content);
		$eng->setContent($content);
		$node->pop();
	}

	public function __construct($tagLib) {
		$tagLib->setTagHandlerFunc("ucase", "tag_UCASE", $this);
		$tagLib->setTagHandlerFunc("lcase", "tag_LCASE", $this);
		$tagLib->setTagHandlerFunc("strreplace", "tag_REPLACE", $this);
		$tagLib->setTagHandlerFunc("strrep", "tag_REPLACE", $this);
	}
}
?>